<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <child1></child1>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      const Child2 = {
        template: `
          <div>child2组件 - {{ $root.count }}</div>
        `,
        mounted() {
          // 可以通过this.$root的方式，在任意组件获取根实例
          // console.log(this.$root.count);
          // this.$root.fn();
          console.log(this.$parent.msg);
        },
      };

      const Child1 = {
        template: `
          <div>child1组件 - <child2></child2></div>
        `,
        data() {
          return {
            msg: "hello",
          };
        },
        components: {
          Child2,
        },
      };

      new Vue({
        el: "#app",
        data: {
          count: 10,
        },
        components: {
          Child1,
        },
        // mounted() {
        //   console.log(this);
        // },
        methods: {
          fn() {
            console.log(123);
          },
        },
      });
    </script>
  </body>
</html>
